﻿'------------------------------
' Hien thi 5 tin moi nhat
'------------------------------
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Namespace NVPortal.Modules.NVProduct

    Public MustInherit Class SettingCustomeDisplaySpecial
        Inherits DotNetNuke.Entities.Modules.ModuleSettingsBase


#Region "Event Handlers"
        Public Overrides Sub LoadSettings()
            Try


                If (Page.IsPostBack = False) Then

                    BindddlCategories()

                    If CType(ModuleSettings("ProductCategorySetting"), String) <> "" Then
                        Me.ddlCategory.Items.FindByValue(ModuleSettings("ProductCategorySetting")).Selected = True
                    End If
                    If IsNumeric(ModuleSettings("ProductDisplayPageSetting")) Then
                        Me.txtDisplayNewsPage.Text = ModuleSettings("ProductDisplayPageSetting")
                    End If

                    If CType(ModuleSettings("ProductDisplayStyleSetting"), String) <> "" Then
                        Me.ddlDisplayStyle.Items.FindByValue(ModuleSettings("ProductDisplayStyleSetting")).Selected = True
                    End If

                    If CType(ModuleSettings("ProductImageValueSetting"), String) <> "" Then
                        Me.txtImageWidth.Text = Split(ModuleSettings("ProductImageValueSetting"))(0)
                        Me.txtImageHeight.Text = Split(ModuleSettings("ProductImageValueSetting"))(1)
                    End If

                    If CType(ModuleSettings("ProductDisplayNumberSetting"), String) <> "" Then
                        Me.txtDisplayRow.Text = ModuleSettings("ProductDisplayNumberSetting")
                    End If
                End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' UpdateSettings saves the modified settings to the Database
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''		[cnurse]	10/22/2004	created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Overrides Sub UpdateSettings()
            Try
                Dim objModules As New DotNetNuke.Entities.Modules.ModuleController

                objModules.UpdateModuleSetting(ModuleId, "ProductCategorySetting", Me.ddlCategory.SelectedValue)
                If IsNumeric(Me.txtDisplayNewsPage.Text) Then
                    objModules.UpdateModuleSetting(ModuleId, "ProductDisplayPageSetting", Me.txtDisplayNewsPage.Text)
                End If
                objModules.UpdateModuleSetting(ModuleId, "ProductDisplayStyleSetting", Me.ddlDisplayStyle.SelectedValue)
                objModules.UpdateModuleSetting(ModuleId, "ProductImageValueSetting", IIf(Trim(Me.txtImageWidth.Text) <> "", Trim(Me.txtImageWidth.Text), "0") & " " & IIf(Trim(Me.txtImageHeight.Text) <> "", Trim(Me.txtImageHeight.Text), "0"))
                objModules.UpdateModuleSetting(ModuleId, "ProductDisplayNumberSetting", IIf(Trim(Me.txtDisplayRow.Text) <> "", Trim(Me.txtDisplayRow.Text), "1"))

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Private Sub BindddlCategories()
            Dim ctlNewsCategories As New NV_ProductCategoriesController
            Dim arrNewsCategories As New ArrayList
            arrNewsCategories = ctlNewsCategories.GetAll(PortalId)
            Dim arrTemp As New ArrayList
            Dim objNewsCategories As CatInfo
            Dim objNewsCategoriesTemp As CatInfo

            If arrNewsCategories.Count > 0 Then
                For Each objNewsCategories In arrNewsCategories
                    If objNewsCategories.ParentId = 0 Then
                        arrTemp.Add(objNewsCategories)
                        For Each objNewsCategoriesTemp In arrNewsCategories
                            If objNewsCategoriesTemp.ParentId = objNewsCategories.CategoryID Then
                                objNewsCategoriesTemp.CategoryName = "--" & objNewsCategoriesTemp.CategoryName
                                arrTemp.Add(objNewsCategoriesTemp)
                            End If
                        Next
                    End If
                Next
            End If

            Me.ddlCategory.DataSource = arrTemp
            Me.ddlCategory.DataTextField = "CategoryName"
            Me.ddlCategory.DataValueField = "CategoryId"
            Me.ddlCategory.DataBind()
            Me.ddlCategory.Items.Insert(0, New ListItem("--Tất cả thư mục--", 0))
        End Sub

#End Region


    End Class

End Namespace
